<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>无new调用</title>
</head>
<body>
<script>
    var pencil = (function () {
        var instance

        class pencil {
            constructor() {
                this.buytime="小学一年级买的"
            }
        }

        return function (msg){
            console.log(msg)
            return  instance || (instance = new pencil())
        }
    })()
    var p1=new pencil("小学一年级我买了它")
    var p2=new pencil("十年后我又从书包里拿出来")
    console.log(p1===p2)
    if(p1===p2){
        console.warn("同一只铅笔，从未改变过；这就是单例模式，无论怎么new 永远都是一个")
    }
</script>
</body>
</html>